/**
 * Created by wangshuyi on 2016/12/27.
 */

'use strict';

/**
 * 公众号
 */

const uuid = require('uuid');
const mongoose = require('../util/mongoDB'),
    Schema = mongoose.Schema;
const config = require('../../config/config');

const storeSchema = new Schema({
    code: {type: String},           //编码
    name: {type: String},                          //文本
});

const schema = new Schema({
    _id: {type: String, default: uuid.v4},
    code: {type: String, default: uuid.v4},       //编码

    eventName: {type: String},                        //活动名称
    eventDateStart: {type: Date},                     //有效期
    eventDateEnd: {type: Date},                       //有效期
    limitNum: {type: Number},                         //次数限制
    intro: {type: String},                            //活动说明
    receiveDate: {type: Date},                        //领奖期限
    needPoint: {type: Number},                        //抽奖所需要积分
    gameType: {type: String},                         //所属游戏

    backgroundImg: {type: String},                   //背景图
    couponImg: {type: String},                       //礼券图
    backgroundColor: {type: String},                 //背景色
    panelColor: {type: String},                      //券板色
    couponColor1: {type: String},                    //礼券色1
    couponColor2: {type: String},                    //礼券色2

    store: [storeSchema],                            //参加门店

    officialAccount: {type: String, ref: "OfficialAccount"},            //所属公众号
    state: {type: Number, default: 1},           //是否有效
    createTime: {type: Date, default: Date.now},    //创建时间
    creater: {type: String, ref: "User", default: config.dbUser.robot._id},          //创建者
    updateTime: {type: Date, default: Date.now},  //最后更新时间
    updater: {type: String, ref: "User", default: config.dbUser.robot._id}         //最后更新者
});

const model = mongoose.model('PrizeEvent', schema);


module.exports = model;